package com.example.controller;

import com.example.entity.Result;
import com.example.entity.User;
import com.example.service.UserService;
import com.example.utils.ResultUtils;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

/**
 * @Author: John
 * @Date 2019/7/20 13:56
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    UserService userService;

    @PostMapping("/insert")
    @ApiOperation(value = "插入一个用户")
    public void insert(@RequestBody User user){
        userService.insert(user);
    }

    @ApiOperation(value = "测试多对多")
    @GetMapping("/getUsersByRoleID")
    public List<User> getUsersByRoleID(int roleID){
        return userService.getUsersByRoleID(roleID);
    }



    /**
     * 用户查询.
     * @return
     */
    @RequestMapping("/userList")
    @RequiresPermissions("userInfo:view")//权限管理;
    public ModelAndView userInfo(){
        return new ModelAndView("/shiro/userInfo");
    }

    /**
     * 用户添加;
     * @return
     */
    @RequestMapping("/userAdd")
    @RequiresPermissions("userInfo:add")//权限管理;
    public ModelAndView userInfoAdd(){
        return new ModelAndView("/shiro/userInfoAdd");
    }

    /**
     * 用户删除;
     * @return
     */
    @RequestMapping("/userDel")
    @RequiresPermissions("userInfo:del")//权限管理;
    public ModelAndView userDel(){
        return new ModelAndView("/shiro/userInfoDel");
    }


    @RequestMapping("/getByName")
    @ApiOperation(value = "查找用户")
    public Result getByName(String userName){
        return ResultUtils.success(userService.getByName(userName));
    }
}
